package com.controller;

import com.pojo.Goods2;
import com.pojo.Result;
import com.service.Goods2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 查询商品
 * @author lifeng
 * @create 2022-11-21 18:54
 */
@RestController
@RequestMapping("/goods")
@CrossOrigin
public class Goods2Controller {

    @Autowired
    private Goods2Service goods2Service;

    @GetMapping("/goodsList")
    public Result findAllGoods(){
        Result result = new Result();
        List<Goods2> list = goods2Service.findAllGoods();
        if (list != null){
            //查询成功
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(list);
        }else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @GetMapping("/goodsList/{typeId}")
    public Result findAllGoodsByTypeId(@PathVariable Integer typeId){
        List<Goods2> list = goods2Service.findAllGoodsByTypeId(typeId);
        Result result = new Result();
        if (result != null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(list);
        }else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @PostMapping("/getToken/{token}")
    public String findToken(@PathVariable String token){
        System.out.println(token);
        return token;
    }



}
